package com.sanley.piss.web.service;


import com.sanley.piss.mapper.EducationalBackgroundMapper;
import com.sanley.piss.model.ServiceImpl;
import com.sanley.piss.model.StringUtil;
import com.sanley.piss.model.exceptionUtil.exception.ServiceException;
import com.sanley.piss.model.exceptionUtil.json.ResultEnum;
import com.sanley.piss.model.po.EducationalBackground;
import com.sanley.piss.web.service.mapper.IEducationalBackgroundService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Create By  on 2021/3/13.
 * @author 张凯大天才
 */
@Service
@Primary
public class EducationalBackgroundServiceImpl extends ServiceImpl<EducationalBackgroundMapper, EducationalBackground> implements IEducationalBackgroundService {


    @Override
    public void insert(EducationalBackground educationalBackground, Integer userId) {
        educationalBackground.setEmployeeId(userId);
        baseMapper.insert(educationalBackground);
    }

    @Override
    public void batchInsert(List<EducationalBackground> lists) {
        lists.forEach(list->{
            list.setGmtCreate(LocalDateTime.now());
        });
        baseMapper.batchInsert(lists);
    }

    @Override
    public EducationalBackground selectById(Integer id) {
        EducationalBackground educationalBackground = baseMapper.selectById(id);
        if (StringUtil.isNull(educationalBackground)) {
            throw new ServiceException(ResultEnum.roleIsNull);
        }
        return educationalBackground;
    }


}
